<?php
if(!isset($iWasThere))
{
	die("bang bang !");
}

Load()->model('model');

class {table}_model extends Model {
	protected $table = '{table}';
	protected $fields = array({fields});
	protected $primaryKey = '{primary_key}';

	function __construct() {
		parent::__construct();
	}

     function sort_{table}() {
		$query = $this->select();
        $this->query($query->sql());
		return $this->fetch();
     }

     function {table}($id) {
     	$query = $this->select()->where(array($this->primaryKey => $id))->limit(1);
        $this->query($query->sql(), $query->getParameters());
        return $this->fetch();
     }

     function add_{table}($req) {
	     //array("name" => $req['name'], ...)
	    
		foreach ($this->fields as $field) {
		 	if (isset($req[$field])) {
		 		$fields[$field] = $req[$field];
			}
		}
    	
		$this->insert($fields);
    	return true;
     }

     function edit_{table}($req) {
	    //array("name" => $req['name'], ...)
		
	    foreach ($this->fields as $field) {
		 	if (isset($req[$field])) {
		 		$updates[$field] = $req[$field];
			}
		}
		
    	$this->update($updates, $req['id']);
    	return true;
     }

     function rm_{table}($id) {
    	$this->delete(array('id' => $id));
    	return true;
     }

}

?>
